package com.jar.exercise.多线程.AQS.reentrantlock;

import java.util.concurrent.TimeUnit;

public class Main {
	public static void main(String[] args) {
		Human human = new Human();

		new Thread(() -> {
			try {
				human.drink();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}, "A").start();

		new Thread(() -> {
			try {
				human.say();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}, "B").start();

	}

}


class Human {
	/*public synchronized static void say() throws InterruptedException {
		TimeUnit.SECONDS.sleep(2);
		System.out.println(Thread.currentThread().getName() + "*****say*****");
	}*/

	public void say() throws InterruptedException {
		synchronized (Human.class) {
			TimeUnit.SECONDS.sleep(2);
			System.out.println(Thread.currentThread().getName() + "*****say*****");
		}
	}

	public void drink() throws InterruptedException {

		synchronized (Human.class) {
			TimeUnit.SECONDS.sleep(3);
			System.out.println(Thread.currentThread().getName() + "*****drink****");
		}
	}
}